#ifndef LIBRARY_LIBRARIANS_H_
#define LIBRARY_LIBRARIANS_H_

#include <QRunnable>
#include <QDebug>

#include "Library.h"

class Worker : public QRunnable {
    static size_t N;
    volatile bool isInterrupted;
    volatile bool stopped;

protected:
    const size_t id;
public:
    virtual void run() {
        while(!isInterrupted)
            action();
        stopped = true;
    }

    Worker() : isInterrupted(false),
        stopped(false), id(N++) {
        setAutoDelete(true);
    }

    void interrupt() {
        isInterrupted = true;
    }

    virtual void action() = 0;
    virtual ~Worker(){}
};

class Reader : public Worker {
    Library& library;
public:
    explicit Reader(Library &library);
    virtual void action();
};

class Writer : public Worker
{
    Library& library;
public:
    explicit Writer(Library &library);
    virtual void action();
};

#endif // LIBRARY_LIBRARIANS_H_
